package com.fedex.longitude.domain;

import static java.util.Collections.emptyList;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;

import java.util.ArrayList;
import java.util.List;

public class NavigatorNode extends Navigator {
	private List<Navigator> _navigatorItems;
	private String _name;

	public NavigatorNode(String name) {
		_name = name;
	}

	@Override
	public String getName() {
		return _name;
	}

	public List<Navigator> getNavigators() {
		if (_navigatorItems == null) {
			return emptyList();
		}
		return _navigatorItems;
	}

	public Boolean hasNavigators() {
		return isNotEmpty(_navigatorItems);
	}

	public List<Navigator> addNavigator(Navigator navigator) {
		if (_navigatorItems == null) {
			_navigatorItems = new ArrayList<Navigator>();
		}
		_navigatorItems.add(navigator);
		return _navigatorItems;
	}

	public List<Navigator> removeNavigatorItem(Navigator navigator) {
		if (_navigatorItems != null) {
			_navigatorItems.remove(navigator);

			if (_navigatorItems.isEmpty()) {
				_navigatorItems = null;
			}
		}
		return _navigatorItems;
	}
}
